var menulist = [{
    id: 10,
    text: '销售中'
}, {
    id: 24,
    text: '未上架'
}, {
    id: 3,
    text: '审核中'
}, ];
var ns;
var app = new Vue({
    el: '#app',
    data: {
        menulist: this.menulist,
        keywords: '',
        //sortby: 1,
        current_sortby:1,
        businessid: '2',
        status: 10,
        sortorders: [
            { title: '默认', index: 5, is_active: true },
            { title: '库存', index:1, is_active: false, sort_by_price: 1 },
            { title: '销量', index: 2, is_active: false, sort_by_price: 1 },
            { title: '成交额', index: 3, is_active:false, sort_by_price: 1 },
            // { title: '筛选', index: 4, is_active: false },
        ],
    },
    methods: {
      get_data:function(){
        //alert(this.status);
       this.openProductItems();
      },
      //调用商品列表页面
      openProductItems: function() {
          var height = $api.offset($api.byId('top_menus')).h;
          api.openFrame({
              name: 'dl_productitems',
              url: './dl_productitems.html',
              rect: {
                  x: 0,
                  y: height+80,
                  w: 'auto',
                  h: 'auto'
              },
              pageParam:{
                status:this.status,
                sortorder:this.current_sortby
              }
          });
      },
        //导航栏切换
      product_search: function(title, id, index) {
            var that = this;
            that.status = id;
            var zt_box = $api.byId('top_menus');
            var zhuangtai = $api.dom(zt_box, '.menu_chk');
            $api.removeCls(zhuangtai, 'menu_chk');
            var obj = $api.byId('box' + index);
            $api.addCls(obj, 'menu_chk');
            api.sendEvent({
                name: 'reloadclassproductlist',
                extra: {
                    status:that.status

                }
            });
        },

        //排序方式
      search_sort: function(item) {
            var that = this;
            for (var i = 0; i < that.sortorders.length; i++) {
                that.sortorders[i].is_active = false;
            }
            item.is_active = true;
            that.current_sortby = item.index;
            //alert(item.index);
            //alert(item.sort_by_price);
            if (item.index == 1||item.index == 2||item.index == 3) {
                //库存默认降序
                if (item.index == 1&&item.sort_by_price==1 ) {
                    item.sort_by_price = 3;
                    that.current_sortby =4;
                }//库存降序
                else if(item.index == 1&&item.sort_by_price==2 ){
                  item.sort_by_price = 3;
                  that.current_sortby = 4;
                }//库存升序
                else if(item.index == 1&&item.sort_by_price==3 ){
                  item.sort_by_price = 2;
                  that.current_sortby = 7;
                }  //销量默认降序
                else if (item.index == 2&&item.sort_by_price==1 ) {
                    item.sort_by_price = 3;
                    that.current_sortby =2;
                }//销量降序
                else if(item.index == 2&&item.sort_by_price==2 ){
                  item.sort_by_price = 3;
                  that.current_sortby = 2;
                }//销量升序
                else if(item.index == 2&&item.sort_by_price==3 ){
                  item.sort_by_price = 2;
                  that.current_sortby = 9;
                } //成交额默认降序
                else if (item.index == 3&&item.sort_by_price==1 ) {
                    item.sort_by_price = 3;
                    that.current_sortby =3;
                }//成交额降序
                else if(item.index == 3&&item.sort_by_price==2 ){
                  item.sort_by_price = 3;
                  that.current_sortby = 3;
                }//成交额升序
                else if(item.index == 3&&item.sort_by_price==3 ){
                  item.sort_by_price = 2;
                  that.current_sortby = 8;
                }
                else{
                  that.current_sortby = 2;
                }



            }
            else {
              that.current_sortby = 2;
            }
            //alert(that.current_sortby);
            api.sendEvent({
                name: 'reloadproductlist',
                extra: {
                    // status:this.status,
                    sortOrder: that.current_sortby
                }
            });
          },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.get_data();
};
